package thread.demo01.base;

public class SynchronizedDemo1 extends Thread {

	// static
	private static int count = 5;

	// synchronized
	@Override
	public synchronized void run() {
		count--;
		System.out.println(this.currentThread().getName() + " count:" + count);
	}

	public static void main(String[] args) {
		SynchronizedDemo1 myThread = new SynchronizedDemo1();
		SynchronizedDemo1 myThread2 = new SynchronizedDemo1();
		
		Thread thread1 = new Thread(myThread, "thread1");
		Thread thread2 = new Thread(myThread2, "thread2");
		Thread thread3 = new Thread(myThread, "thread3");
		Thread thread4 = new Thread(myThread2, "thread4");
		Thread thread5 = new Thread(myThread, "thread5");
		thread1.start();
		thread2.start();
		thread3.start();
		thread4.start();
		thread5.start();
	}
}
